<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>同步数据库数据到 es</title>
    <link rel="stylesheet" type="text/css" href="/static/hplus/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/hplus/css/plugins/iCheck/custom.css">
    <link rel="stylesheet" type="text/css" href="/static/hplus/css/style.css">
    <link rel="stylesheet" type="text/css" href="/static/layer/skin/layer.css">
    <style type="text/css">
        .form-control {width: 200px;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>同步数据库数据到 es</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" onsubmit="return false">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">数据表</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="table">
                                    <option value="">…请选择…</option>
                                    {foreach $tables as $item}
                                    <option value="{$item.TABLE_NAME}">{$item.TABLE_COMMENT}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">分页大小</label>
                            <div class="col-sm-10">
                                <input type="text" id="size" class="form-control" value="1000" autocomplete="off">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">字段名</label>
                            <div class="col-sm-10">
                                <input type="text" id="field" class="form-control" placeholder="查询要同步数据的字段名" autocomplete="off">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">字段值</label>
                            <div class="col-sm-10">
                                <input type="text" id="field_value" class="form-control" placeholder="查询要同步数据的字段值" autocomplete="off">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">比较关系</label>
                            <div class="col-sm-10">
                                <div class="radio i-checks">
                                    <label class>
                                        <div class="iradio_square-green">
                                            <input type="radio" value="=" name="rel" checked style="position: absolute; opacity: 0;">
                                            <ins class="iCheck-helper"></ins>
                                        </div>
                                        等于</label>
                                    <label class>
                                        <div class="iradio_square-green">
                                            <input type="radio" value=">" name="rel" style="position: absolute; opacity: 0;">
                                            <ins class="iCheck-helper"></ins>
                                        </div>
                                        大于</label>
                                    <label class>
                                        <div class="iradio_square-green">
                                            <input type="radio" value="<" name="rel" style="position: absolute; opacity: 0;">
                                            <ins class="iCheck-helper"></ins>
                                        </div>
                                        小于</label>
                                    <label class>
                                        <div class="iradio_square-green">
                                            <input type="radio" value="like" name="rel" style="position: absolute; opacity: 0;">
                                            <ins class="iCheck-helper"></ins>
                                        </div>
                                        模糊匹配</label>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-6 col-sm-offset-2">
                                <input class="btn btn-primary" type="button" id="save" value="同步">
                                <input class="btn btn-danger" type="button" id="del" value="删除">
                                <span style="color: #7F007F">(如果指定条件，同步和删除都是操作符合条件的数据，如果不指定，同步整个表数据，只删除表对应的索引)</span>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="/static/hplus/js/jquery.min.js?v={php}echo time(){/php}"></script>
<script type="text/javascript" src="/static/hplus/js/plugins/iCheck/icheck.min.js?v={php}echo time(){/php}"></script>
<script type="text/javascript" src="/static/layer/layer.js?v={php}echo time(){/php}"></script>
<script type="text/javascript">
    $(function () {
        $(".i-checks").iCheck({checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green"});
        $('#save').click(function () {
            let $table = $('#table');
            if ($table.val() === '') {
                layer.msg('请选择数据表', {icon: 5, time: 1000}, function () {
                    $table.focus();
                });
                return false;
            }
            $.ajax({
                type: 'post', cache: false, dataType: 'json',
                url: '{:url("index")}',
                data: {'table': $table.val(), 'size': $('#size').val(), 'field': $('#field').val(), 'field_value': $('#field_value').val(), 'rel': $('[name="rel"]:checked').val()},
                beforeSend: function () {
                    layer.load(2, {shade: [0.3, '#fff']})
                },
                success: function (data) {
                    layer.closeAll('loading')
                    if (data.code === 200) {
                        layer.confirm(data.message + '<br />是否继续同步？', {
                            btn: ['是', '否'],
                            shade: false,
                            closeBtn: 0
                        }, function () {
                            location.reload();
                        }, function () {
                        });
                    } else {
                        layer.msg(data.message, {icon: 5, time: 1000});
                    }
                }
            });
        });
        $('#del').click(function () {
            layer.confirm('确定要删除吗？', {
                btn: ['确定', '取消'],
                shade: [0.8, '#efefef'],
                closeBtn: 0
            }, function () {
                let $table = $('#table');
                if ($table.val() === '') {
                    layer.msg('请选择数据表', {icon: 5, time: 1000}, function () {
                        $table.focus();
                    });
                    return false;
                }
                $.ajax({
                    type: 'post', cache: false, dataType: 'json',
                    url: '{:url("del")}',
                    data: {'table': $table.val(), 'field': $('#field').val(), 'field_value': $('#field_value').val(), 'rel': $('[name="rel"]:checked').val()},
                    beforeSend: function () {
                        layer.load(2, {shade: [0.3, '#fff']})
                    },
                    success: function (data) {
                        layer.closeAll('loading')
                        if (data.code === 200) {
                            layer.msg(data.message, {icon: 1, time: 1000})
                        } else {
                            layer.msg(data.message, {icon: 5, time: 1000})
                        }
                    }
                });
            })
        });
    });
</script>
</html>
